package com.xhh.enjoyapp.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.xhh.enjoyapp.Bean.User;
import com.xhh.enjoyapp.MainActivity;
import com.xhh.enjoyapp.R;

import java.util.Timer;
import java.util.TimerTask;

import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobUser;

/**
 * @description
 * @author: weiXhh
 * @create: 2020-05-13 11:45
 **/
public class Splash extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        Timer timer = new Timer();
        timer.schedule(timerTask,2000);

        // 初始化Bmob id
        Bmob.initialize(this,"d3e1bf8031b6974daf3e37a8b57529dd");

    }
    // 定时任务
    TimerTask timerTask = new TimerTask() {
        @Override
        public void run() {
//            Intent intent = new Intent(Splash.this, MainActivity.class);
//            startActivity(intent);
            // 如果已经登录， 跳到主界面，没有登录，跳转到登录界面

            BmobUser bmobUser = BmobUser.getCurrentUser(User.class);

            if(bmobUser != null){
                startActivity(new Intent(Splash.this, MainActivity.class));

            } else {

                // 没有登录
                startActivity(new Intent(Splash.this, Login.class));
            }
        }
    };
}
